﻿Imports System
Imports System.IO
Imports System.Data.SqlServerCe
Imports System.Drawing
Imports System.Collections
Imports System.Windows.Forms
Imports System.Data
Imports System.Data.Common
Imports System.Reflection

Public Class frmProject
    Private db As DatabaseFactory = New DatabaseFactory

    Sub initScreen()
        Dim dtResult As New DataTable
        Dim lstViewCust As New ListViewItem

        dtResult = findProjects(Nothing, "ACTIVE")
        lvProjectList.Items.Clear()

        If dtResult.Rows.Count > 0 Then

            For Each dataRow As DataRow In dtResult.Rows
                Dim projectName As String = dataRow.Item("PROJECT_NAME")

                lstViewCust = Me.lvProjectList.Items.Add(New ListViewItem(projectName))
                Dim statusCode As String = ""

                statusCode = dataRow.Item("STATUS_CODE")

                lstViewCust.SubItems.Add(statusCode)
                lstViewCust.Tag = dataRow.Item("PROJECT_ID")
            Next dataRow
        End If
    End Sub

    Private Sub frmProject_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        initScreen()
        'loadPdaInidata()
    End Sub

    Sub loadPdaInidata()
        Dim output As String = ""

        Dim strAppDir As String = Path.GetDirectoryName([Assembly].GetExecutingAssembly().GetModules(0).FullyQualifiedName)
        Try
            Dim fsRead As New FileStream(strAppDir + "\eqam.DAT", FileMode.Open, FileAccess.Read)
            Dim data_reader As New StreamReader(fsRead)
            Dim line As String = data_reader.ReadLine()

            While Not line Is Nothing
                _PDA_CODE = line
                line = data_reader.ReadLine()
            End While

            data_reader.Close()

        Catch ex As Exception
            Dim fsWrite As New FileStream(strAppDir, FileMode.Create)
            fsWrite.Close()
            MessageBox.Show("Application Init Problem", "E-QAM Init Problem")
        End Try
    End Sub

    Private Sub lvProjectList_ItemActivate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvProjectList.ItemActivate
        projectSelected()
    End Sub

    Private Sub btnProjectSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProjectSelect.Click
        projectSelected()
    End Sub

    Sub projectSelected()
        Dim sic As ListView.SelectedIndexCollection
        sic = lvProjectList.SelectedIndices()
        If sic.Count <> 0 Then
            Me.Text = lvProjectList.Items(sic.Item(0)).SubItems(0).Text
            _PROJECT_ID = lvProjectList.Items(sic.Item(0)).Tag
            _PROJECT_NAME = lvProjectList.Items(sic.Item(0)).SubItems(0).Text

            _FROM_SCREEN_ID = _SCREEN_ID
            _SCREEN_ID = SCREEN_LOGIN

            frmLogin.Show()
            frmLogin.initScreen()
            Me.Hide()
        End If
    End Sub
End Class